package com.ysd.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.sun.xml.internal.bind.v2.runtime.reflect.Lister.Pack;
import com.ysd.entity.DesignerInfo;
import com.ysd.entity.ProductclassifiCationTable;
import com.ysd.entity.Productdetailsinfo;
import com.ysd.util.DBManager;

public class DesignerInfoimpl {
	public List<DesignerInfo> getDesignerInfo(){
		List<DesignerInfo> list = new ArrayList<DesignerInfo>();
		Connection conn = DBManager.grtConnection();
		Statement st = null;
		ResultSet rs = null;
		try {
			st = conn.createStatement();
			String sql="select*from DesignerInfo";
			st.executeQuery(sql);
			rs =st.executeQuery(sql);
			while(rs.next()) {
				int designerid = rs.getInt("designerid");
				String designerName = rs.getString("designerName");
				String designerTitle = rs.getString("designerTitle");
				String designerImg= rs.getString("designerImg");
				 DesignerInfo DesignerInfo = new DesignerInfo(designerid,designerName,designerTitle, designerImg );
				 list.add(DesignerInfo);
			}
			return list;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}finally {
			DBManager.closeAll(conn, st, rs);
		}
		
	}
	/**
	 * 分页
	 * 
	 * */
	
	public List<DesignerInfo> getDesignerInfoByPage(int page,int size){
		List<DesignerInfo> list = new ArrayList<DesignerInfo>();
		Connection conn = DBManager.grtConnection();
		Statement st = null;
		ResultSet rs = null;
		try {
			st = conn.createStatement();
			String sql="select*from DesignerInfo LIMIT "+(page-1)*size+" ,"+size;
			st.executeQuery(sql);
			rs =st.executeQuery(sql);
			while(rs.next()) {
				int designerid = rs.getInt("designerid");
				String designerName = rs.getString("designerName");
				String designerTitle = rs.getString("designerTitle");
				String designerImg= rs.getString("designerImg");
				 DesignerInfo DesignerInfo = new DesignerInfo(designerid,designerName,designerTitle, designerImg );
				 list.add(DesignerInfo);
			}
			return list;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}finally {
			DBManager.closeAll(conn, st, rs);
		}
		
	}
	
	public int deleteDesignerInfo(int cId) {
		return DBManager.executeUpdate("DELETE from designerinfo where designerid="+cId);		
	}
	public int addproduct(DesignerInfo pc) {
		return DBManager.executeUpdate("INSERT into designerinfo VALUES(null,'"+pc.getDesignerName()+"','"+pc.getDesignerTitle()+"','"+pc.getDesignerImg()+"')");
	}
	public List<DesignerInfo> getDesignerInfo(String name){
		List<DesignerInfo> pcList = new ArrayList<DesignerInfo>();
		Connection conn = DBManager.grtConnection();
		Statement st = null;
		ResultSet rs = null;
		try {
			st = conn.createStatement();
			rs = st.executeQuery("select * from DesignerInfo where designerName = '"+name+"'");
			while (rs.next()) {
				int designerid = rs.getInt("designerid");
				String designerName = rs.getString("designerName");
				String designerTitle = rs.getString("designerTitle");
				String designerImg= rs.getString("designerImg");
				 DesignerInfo pc = new DesignerInfo(designerid,designerName,designerTitle, designerImg );
				pcList.add(pc);
			}
			return pcList;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}finally {
			DBManager.closeAll(conn, st, rs);
		}
	}
	public DesignerInfo getDesignerInfobyid(int cateId) {
		DesignerInfo pc = null;
		Connection conn = DBManager.grtConnection();
		Statement st = null;
		ResultSet rs = null;
		try {
			st = conn.createStatement();
			rs= st.executeQuery("select * from DesignerInfo where designerid="+cateId);
			while (rs.next()) {
				int designerid = rs.getInt(1);
				String designerName = rs.getString(2);
				String designerTitle = rs.getString(3);
				String designerImg = rs.getString(4);
				
				pc = new DesignerInfo(designerid, designerName, designerTitle, designerImg);
			}
			return pc;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}finally {
			DBManager.closeAll(conn, st, rs);
		}
	}
	public int updateDesignerInfo(DesignerInfo pc) {
		return DBManager.executeUpdate("update DesignerInfo set designerName='"+pc.getDesignerName()+"',designerTitle='"+pc.getDesignerTitle()+"' ,designerImg='"+pc.getDesignerImg()+"' where designerid="+pc.getDesignerid());
	}

	
}
